package com.example.demo.createanddestroyobjects.one.one2;

import java.util.EnumSet;
import java.util.Objects;
import java.util.Set;

/**
 * 抽象层次构建器
 */
public class AbstaractPizza {
    public enum Topping {HAM, ONION, PEPPER}

    final Set<Topping> toppings;

    abstract static class Builder<T extends Builder<T>> {
        EnumSet<Topping> toppings = EnumSet.noneOf(Topping.class);

        public T addToping(Topping topping) {
            toppings.add(Objects.requireNonNull(topping));
            return self();
        }

        abstract AbstaractPizza build();

        protected abstract T self();
    }

    AbstaractPizza(Builder<?> builder) {
        toppings = builder.toppings.clone();
    }



//    public class NyPizza extends AbstaractPizza{
//        public  enum  Size {SMALL,LA}
//        private final  Size size;
//        public static class Builder extends  AbstaractPizza.Builder<Builder>{
//            private  final  Size size;
//            public Builder(Size size){
//                this.size = Objects.requireNonNull(size);
//            }
//            @Override
//            public NyPizza build(){
//                return  new NyPizza(this);
//            }
//            @Override
//            protected Builder self(){return  this;}
//        }
//        private NyPizza(Builder builder){
//            super(builder);
//            size = builder.size;
//        }
//    }
}
